﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRM.WEB
{
    public partial class TaskScheduled : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Convert.ToBoolean(ConfigurationManager.AppSettings["InitEffectiveDateFlag"]))
            //{
            //    var startDate = Convert.ToDateTime(ConfigurationManager.AppSettings["InitEffectiveDate"]);
            //    var endDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));

            //    var res = new StringBuilder();

            //    while (startDate <= endDate)
            //    {
            //        string ids = string.Empty;
            //        string errorStr = string.Empty;
            //        int count1;
            //        int count2;
            //        int count3;
            //        int count4;
            //        int count5;
            //        CommonClass.Common.GetTakeEffectData(ConfigurationManager.AppSettings["SupplierId"], startDate,
            //            startDate.AddDays(1), ref ids, ref errorStr, out count1, out count2,
            //            out count3, out count4, out count5, true);
            //        res.AppendFormat(
            //            "日期{6}-{7}中，生效订单总数量：{5}\r\n新增成功数量： {0}\r\n新增失败数量：{1}\r\n更新成功数量：{2}\r\n更新失败数量：{3}\r\n{4}",
            //            count1,
            //            count2, count3, count4, string.IsNullOrEmpty(errorStr) ? string.Empty : errorStr, count5,
            //            startDate.ToString("yyyy-MM-dd"), startDate.AddDays(1).ToString("yyyy-MM-dd"));
            //        startDate = startDate.AddDays(1);
            //    }
            //    Response.Write(res.ToString());
            //}
            //else
            //{
            //    var res = new StringBuilder();
            //    var startDate = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));

            //    string ids = string.Empty;
            //    string errorStr = string.Empty;
            //    int count1;
            //    int count2;
            //    int count3;
            //    int count4;
            //    int count5;
            //    CommonClass.Common.GetTakeEffectData(ConfigurationManager.AppSettings["SupplierId"], startDate,
            //        startDate.AddDays(1), ref ids, ref errorStr, out count1, out count2,
            //        out count3, out count4, out count5, true);
            //    res.AppendFormat(
            //        "日期{6}-{7}中，生效订单总数量：{5}\r\n新增成功数量： {0}\r\n新增失败数量：{1}\r\n更新成功数量：{2}\r\n更新失败数量：{3}\r\n{4}",
            //        count1,
            //        count2, count3, count4, string.IsNullOrEmpty(errorStr) ? string.Empty : errorStr, count5,
            //        startDate.ToString("yyyy-MM-dd"), startDate.AddDays(1).ToString("yyyy-MM-dd"));

            //    Response.Write(res.ToString());
            //}
            try
            {

                var startDate = Request["startDate"] ?? string.Empty;
                var endDate = Request["endDate"] ?? string.Empty;
                if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate) &&
                    Convert.ToDateTime(startDate).AddDays(1) == Convert.ToDateTime(endDate))
                {
                    var res = new StringBuilder();

                    string ids = string.Empty;
                    string errorStr = string.Empty;
                    int count1;
                    int count2;
                    int count3;
                    int count4;
                    int count5;
                    var sDate = Convert.ToDateTime(startDate);
                    CommonClass.Common.GetTakeEffectData(ConfigurationManager.AppSettings["SupplierId"], sDate,
                        sDate.AddDays(1), ref ids, ref errorStr, out count1, out count2,
                        out count3, out count4, out count5, true);
                    res.AppendFormat(
                        "日期{6}-{7}中，生效订单总数量：{5}\r\n新增成功数量： {0}\r\n新增失败数量：{1}\r\n更新成功数量：{2}\r\n更新失败数量：{3}\r\n{4}",
                        count1,
                        count2, count3, count4, string.IsNullOrEmpty(errorStr) ? string.Empty : errorStr, count5,
                        sDate.ToString("yyyy-MM-dd"), sDate.AddDays(1).ToString("yyyy-MM-dd"));

                    Response.Write(res.ToString());
                }
                else
                {
                    Response.Write("Para Error.");
                }
            }
            catch (Exception ex)
            {
                Response.Write("URL ERROR: " + ex.Message + ex.StackTrace);
            }
        }
    }
}